import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

public class TestTX {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("IP地址",6379);
        jedis.flushDB();
        Transaction multi = null;
        try {
            multi = jedis.multi();//开启事务
            multi.set("user:name", "haste");
            multi.set("user:age", "18");
            multi.set("user:gender", "1");
            int i = 1/0;
            multi.exec();//执行事务
        } catch (Exception e) {
            multi.discard();
            System.out.println("执行失败");
            e.printStackTrace();
        } finally {
            System.out.println(jedis.get("user:name"));
            multi.close();
        }
    }
}
